package cn.com.czpb.client.module.news.dialog;

import android.app.Activity;
import android.content.Context;
import android.graphics.drawable.BitmapDrawable;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.PopupWindow;

import cn.com.czpb.client.R;
import cn.com.czpb.client.utils.StringUtils;
import cn.com.czpb.client.utils.TUtils;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by 猪猪侠 on 2017/7/5.
 */

public class InputPop extends PopupWindow {
    @BindView(R.id.zq_reply_et_content)
    EditText zqReplyEtContent;

    public interface InputListener {
        void inputstr(String string);
    }
    private InputListener listener;


    public InputPop(Activity a, InputListener h) {
        View view = a.getLayoutInflater().inflate(R.layout.input_pop_layout, null);
        ButterKnife.bind(this,view);
        setContentView(view);
        setWindowLayoutMode(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
        setBackgroundDrawable(new BitmapDrawable());
        this.listener = h;
        setOutsideTouchable(true);

        zqReplyEtContent.setFocusable(true);
        InputMethodManager imm = (InputMethodManager) a.getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS);
    }
    @OnClick({R.id.zq_reply_tv_cancle, R.id.zq_reply_tv_send})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.zq_reply_tv_cancle: {
                zqReplyEtContent.setText("");
                this.dismiss();
            }
            break;
            case R.id.zq_reply_tv_send: {
                String str = zqReplyEtContent.getText().toString();
                if (StringUtils.isEmpty(str)) {
                    TUtils.toast("输入内容不能为空");
                    return;
                }
                if (listener != null) {
                    listener.inputstr(str);
                }
                zqReplyEtContent.setText("");
                this.dismiss();
            }
            break;
        }
    }
}
